/*
 *   Copyright (C) 2010  Jens Kieselbach
 * 
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 * 
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 * 
 *   You may obtain a copy of the License at http://www.gnu.org/licenses/gpl.html
 */

package de.kieselbach.grootional.util

import javax.swing.tree.*

class DatabaseNode extends DefaultMutableTreeNode {

    final static int ROOT = 1
    final static int SCHEMA = 2
    final static int TYPE_TABLE = 3
    final static int TYPE_SYSTEM = 4
    final static int TYPE_VIEW = 5
    final static int TYPE_SYNONYM = 6
    final static int TYPE_UNKNOWN = 7
    final static int TABLE = 8
    final static int COLUMN = 9

    int type
    int dataType
    def name
    def description

    boolean primaryKey

    def tableType
    def tableName

    DatabaseNode(int t, String n) {

        this(t, n, null, true)
    }

    DatabaseNode(int t, String n, String desc) {

        this(t, n, desc, true)
    }

    DatabaseNode(int t, String n, boolean allowschilds) {
    
        this(t, n, null, true)
    }

    DatabaseNode(int t, String n, String desc, boolean allowschilds) {

        super(desc != null ? desc : n)

        type = t
        name = n
        description = desc != null ? desc : n
    }

    // -------------------------------------------------------------

    static int parseTableType(def name) {

        if('TABLE'.equalsIgnoreCase(name)) {
            return TYPE_TABLE
        }
        else if('VIEW'.equalsIgnoreCase(name)) {
            return TYPE_VIEW
        }
        else if('SYNONYM'.equalsIgnoreCase(name)) {
            return TYPE_SYNONYM
        }
        else if('SYSTEM'.equalsIgnoreCase(name) || 'SYSTEM TABLE'.equalsIgnoreCase(name)) {
            return TYPE_SYSTEM
        }
        else {
            return TYPE_UNKNOWN
        }
    }
}

